class MyTrace
{
	/// See: http://haxe.org/doc/cross/trace

	public static function setRedirection() 
	{
		haxe.Log.trace = myTrace;
	}

	static function myTrace(v:Dynamic, ?inf : haxe.PosInfos)
	{

	}

	/**
	 * TODO
	 * - understand what the hell this does
	 *   => Freenode IRC: Gershon's code
	 */
	public static function print_r(obj:Dynamic, ?indent:String="\t") : String
	{
		return Std.is(obj, DisplayObjectContainer) ? print_mc(obj, indent) : print_r(obj, indent);
	}

	public static function print_a(obj:Dynamic, ?indent:String="\t") : String
	{
		//
		var type = obj.constructor;
		//~ var type = Type.typeof(obj.constructor);
		//~ var str : String = Std.string(obj) + " " + type;
		var str : String = "\n"+indent + type;
		
		// Make sure its an object, and not a of class String
		//~ if(!Reflect.isObject(obj) || Std.is(type, TClass(String)) ) 
		if(!Reflect.isObject(obj) || Std.is(obj, String) ) 
			return Std.string(obj) + " " + type;

		for (i in Reflect.fields(obj)) 
		{
			str += "\n"+indent;
			var field = Reflect.field(obj, i) ;
			//~ type = field.constructor;

			if(Reflect.isObject(field)) 
			//~ if(Reflect.isObject(field) || Std.is(field, Array) ) 
			{
					str += indent + "[" + i  + "]" + " => " ;
					str += print_r(field, indent+indent) ;
		
			}
			else 
			{
				str += indent + "["+i+"] => "+field+" "+type;
			}
		}

		return str;
	}

	public static function print_mc(obj:DisplayObjectContainer, ?indent:String="\t") : String
	{
		//
		var str : String = "\n";
		for (i in 0...obj.numChildren) 
		{			
			var child = obj.getChildAt(i);
			if(Std.is(child, DisplayObjectContainer)) 
			{
				str += indent + "[" + child.name  + "]" + " => " + child;
				//~ str += print_mc(cast child, indent+indent);
				str += indent + print_r(cast child, indent+indent);
			}
			else 
			{
				if(Std.is(child,Sprite) || Std.is(child,TextField))
					str += indent + "[" + child.name + "] => " + child + "\n";
			}
		}
		return str;
	}
}
